﻿using System.Globalization;
using System.Windows.Controls;

namespace DimensionsHelper.Client.ValidationRules;

public class ByteValidationRule : ValidationRule
{
    public override ValidationResult Validate(object? value, CultureInfo cultureInfo)
    {
        switch (value)
        {
            case string text when byte.TryParse(text, out _):
            case >= 0 and <= 255:
                return ValidationResult.ValidResult;
            default:
                return new ValidationResult(false, "有效范围是 0-255");
        }
    }
}